﻿using RandomStudent.Extends;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RandomStudent.Controls
{
    /// <summary>
    /// LuckyBoy.xaml 的交互逻辑
    /// </summary>
    public partial class LuckyBoy : UserControl
    {
        RotateTransform tramsform = new RotateTransform();
        public LuckyBoy()
        {
            InitializeComponent();

            this.btnClickMe.RenderTransform = tramsform;
            this.btnClickMe.Click += new RoutedEventHandler(btnClickMe_Click);


        }
        private void btnClickMe_Click(object sender, RoutedEventArgs e)
        {
            DoubleAnimation animation = new DoubleAnimation();
            //
            animation.DecelerationRatio = 0.9;
            //
            double angle = new Random().Next(360 * 10, 360 * 20);
            animation.To = tramsform.Angle + angle;
            animation.Duration = TimeSpan.FromSeconds(9);
            animation.Completed += storyboard_Completed;
            /////1
            //tramsform.BeginAnimation(RotateTransform.AngleProperty, animation);


            ///// 2
            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(animation);
            Storyboard.SetTarget(animation, btnClickMe);
            Storyboard.SetTargetProperty(animation, new PropertyPath("RenderTransform.Angle"));
            storyboard.Begin();
            //storyboard.
            
            storyboard.Children[0].Completed += storyboard_Completed;
        }

        void storyboard_Completed(object sender, EventArgs e)
        {
            PropertyInfo angleProp = sender.GetType().GetProperty("Angle");
            //this.btnClickMe.Resources.
        }
    }
}
